package com.my.controller;


import com.my.pojo.FileInfo;
import com.my.service.IFileInfoService;
import com.my.service.IFolderService;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/user/fileInfoController")
public class FileInfoController extends HttpServlet {

    private String fileName;
    private String creator;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resq) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        HttpSession session = req.getSession();
        fileName = req.getParameter("fileName");
        creator =req.getParameter("creator");
        ServletContext sc = this.getServletContext();
        WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
        IFileInfoService fileInfoService = wac.getBean("fileInfoService", IFileInfoService.class);
        List<FileInfo> infoList = fileInfoService.searchFileInfoByName(fileName,creator);
        session.setAttribute("fileInfoList",infoList);
        resq.sendRedirect("fileSearchResult.jsp");
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resq) throws ServletException, IOException {
        this.doGet(req,resq);
    }
}
